package in.iqing.control.util;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;

import in.iqing.app.R;

/**
 * Created by neavo on 14-3-7.
 */

public class IntentUtil {

	public static synchronized boolean isIntentAvailable(Context ctx, Intent intent) {
		return ctx.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY).size() > 0;
	}

	public static synchronized void startActivity(Activity source, Intent intent) {
		source.startActivity(intent);
		source.overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_from_left);
	}

	public static synchronized void startActivity(Activity source, Class<? extends Activity> target) {
		source.startActivity(new Intent(source, target));
		source.overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_from_left);
	}

	public static synchronized void startActivity(Activity source, Class<? extends Activity> target, Bundle extra) {
		source.startActivity(new Intent(source, target).putExtras(extra));
		source.overridePendingTransition(R.anim.slide_in_from_right, R.anim.slide_out_from_left);
	}

	public static synchronized void startActivityReverse(Activity source, Intent intent) {
		source.startActivity(intent);
		source.overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_from_right);
	}

	public static synchronized void startActivityReverse(Activity source, Class<? extends Activity> target) {
		source.startActivity(new Intent(source, target));
		source.overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_from_right);
	}

	public static synchronized void startActivityReverse(Activity source, Class<? extends Activity> target, Bundle extra) {
		source.startActivity(new Intent(source, target).putExtras(extra));
		source.overridePendingTransition(R.anim.slide_in_from_left, R.anim.slide_out_from_right);
	}
}
